//
//  ZLPhotoPickerBrowserViewController+LF.m
//  AntFarms
//
//  Created by LF on 2017/7/5.
//  Copyright © 2017年 GG. All rights reserved.
//

#import "ZLPhotoPickerBrowserViewController+LF.h"

@implementation ZLPhotoPickerBrowserViewController (LF)
+ (void) showPhotoBrowserInViewController:(UIViewController *)viewController withImages:(NSArray *)imageArray atIndex:(NSInteger)index {
    NSMutableArray *assets = [NSMutableArray arrayWithCapacity:imageArray.count];
    for (id url in imageArray) {
        if ([url isKindOfClass:[UIImage class]]) {
//            NSString *x = [[url componentsSeparatedByString:@"?"] firstObject];
//            ZLPhotoPickerBrowserPhoto *photo = [[ZLPhotoPickerBrowserPhoto alloc] init];
            ZLPhotoPickerBrowserPhoto *photo = [ZLPhotoPickerBrowserPhoto photoAnyImageObjWith:url];
//            photo.photoURL = [NSURL URLWithString:x];
            [assets addObject:photo];

        } else if ([url isKindOfClass:[NSData class]]) {
            UIImage *img = [UIImage imageWithData:url];
            ZLPhotoPickerBrowserPhoto *photo = [ZLPhotoPickerBrowserPhoto photoAnyImageObjWith:img];
            [assets addObject:photo];
        } else if ([url isKindOfClass:[NSString class]]){
            NSString *x = [[url componentsSeparatedByString:@"?"] firstObject];
            ZLPhotoPickerBrowserPhoto *photo = [[ZLPhotoPickerBrowserPhoto alloc] init];
            photo.photoURL = [NSURL URLWithString:x];
            [assets addObject:photo];
        }
    }
    // 图片游览器
    ZLPhotoPickerBrowserViewController *pickerBrowser = [[ZLPhotoPickerBrowserViewController alloc] init];
    // 淡入淡出效果
    pickerBrowser.status = UIViewAnimationAnimationStatusFade;
    // 数据源/delegate
    pickerBrowser.editing = NO;
    pickerBrowser.photos = assets;
    // 能够删除
    //        pickerBrowser.delegate = self;
    // 当前选中的值
    pickerBrowser.currentIndex = index;
    // 展示控制器
    
    if (viewController) {
        [pickerBrowser showPickerVc:viewController];
    } else {
        [pickerBrowser showPickerVc:[UIApplication sharedApplication].keyWindow.rootViewController];
    }
}

//添加微信照片预览特效需要传入图片在windows中的originframe
+ (void) showPhotoBrowserInViewController:(UIViewController *)viewController withImages:(NSArray *)imageArray withImageFrames:(NSMutableArray*)imageFrameAry withImageViews:(NSMutableArray*)imageViews atIndex:(NSInteger)index
{
    NSMutableArray *assets = [NSMutableArray arrayWithCapacity:imageArray.count];
    //    CGRect newFrame = [frame convertRect:from.boundstoView:window];
    for (id url in imageArray) {
        if ([url isKindOfClass:[UIImage class]]) {
            //            NSString *x = [[url componentsSeparatedByString:@"?"] firstObject];
            //            ZLPhotoPickerBrowserPhoto *photo = [[ZLPhotoPickerBrowserPhoto alloc] init];
            ZLPhotoPickerBrowserPhoto *photo = [ZLPhotoPickerBrowserPhoto photoAnyImageObjWith:url];
            //            photo.photoURL = [NSURL URLWithString:x];
            [assets addObject:photo];
            
        } else if ([url isKindOfClass:[NSData class]]) {
            UIImage *img = [UIImage imageWithData:url];
            ZLPhotoPickerBrowserPhoto *photo = [ZLPhotoPickerBrowserPhoto photoAnyImageObjWith:img];
            [assets addObject:photo];
        } else if ([url isKindOfClass:[NSString class]]){
            NSString *x = [[url componentsSeparatedByString:@"?"] firstObject];
            ZLPhotoPickerBrowserPhoto *photo = [[ZLPhotoPickerBrowserPhoto alloc] init];
            photo.photoURL = [NSURL URLWithString:x];
            [assets addObject:photo];
        }
    }
    // 图片游览器
    ZLPhotoPickerBrowserViewController *pickerBrowser = [[ZLPhotoPickerBrowserViewController alloc] init];
    
    // 淡入淡出效果
    pickerBrowser.status = UIViewAnimationAnimationStatusFade;
    // 数据源/delegate
    pickerBrowser.editing = NO;
    pickerBrowser.photos = assets;
    // 能够删除
    //        pickerBrowser.delegate = self;
    // 当前选中的值
    pickerBrowser.currentIndex = index;
    // 展示控制器
    
    if (viewController) {
        [pickerBrowser showPickerVc:viewController];
    } else {
        [pickerBrowser showPickerVc:[UIApplication sharedApplication].keyWindow.rootViewController];
    }
}

+(void)showPhotoBrowserInViewController:(UIViewController *)viewController withImages:(NSArray *)imageArray atIndex:(NSInteger)index andTitle:(NSArray *)titleArray{
    NSMutableArray *assets = [NSMutableArray arrayWithCapacity:imageArray.count];
    for (id url in imageArray) {
        if ([url isKindOfClass:[UIImage class]]) {
            //            NSString *x = [[url componentsSeparatedByString:@"?"] firstObject];
            //            ZLPhotoPickerBrowserPhoto *photo = [[ZLPhotoPickerBrowserPhoto alloc] init];
            ZLPhotoPickerBrowserPhoto *photo = [ZLPhotoPickerBrowserPhoto photoAnyImageObjWith:url];
            //            photo.photoURL = [NSURL URLWithString:x];
            [assets addObject:photo];
            
        } else if ([url isKindOfClass:[NSData class]]) {
            UIImage *img = [UIImage imageWithData:url];
            ZLPhotoPickerBrowserPhoto *photo = [ZLPhotoPickerBrowserPhoto photoAnyImageObjWith:img];
            [assets addObject:photo];
        } else if ([url isKindOfClass:[NSString class]]){
            NSString *x = [[url componentsSeparatedByString:@"?"] firstObject];
            ZLPhotoPickerBrowserPhoto *photo = [[ZLPhotoPickerBrowserPhoto alloc] init];
            photo.photoURL = [NSURL URLWithString:x];
            [assets addObject:photo];
        }
    }
    // 图片游览器
    ZLPhotoPickerBrowserViewController *pickerBrowser = [[ZLPhotoPickerBrowserViewController alloc] init];
    // 淡入淡出效果
    pickerBrowser.status = UIViewAnimationAnimationStatusFade;
    // 数据源/delegate
    pickerBrowser.editing = NO;
    pickerBrowser.photos = assets;
    // 能够删除
    //        pickerBrowser.delegate = self;
    // 当前选中的值
    pickerBrowser.currentIndex = index;
    // 展示控制器
    
    if (viewController) {
        [pickerBrowser showPickerVc:viewController];
    } else {
        [pickerBrowser showPickerVc:[UIApplication sharedApplication].keyWindow.rootViewController];
    }
}
+ (void)NoHandleUrlshowPhotoBrowserInViewController:(UIViewController *)viewController withImages:(NSArray *)imageArray atIndex:(NSInteger)index {
    NSMutableArray *assets = [NSMutableArray arrayWithCapacity:imageArray.count];
    for (id url in imageArray) {
        if ([url isKindOfClass:[UIImage class]]) {
            //            NSString *x = [[url componentsSeparatedByString:@"?"] firstObject];
            //            ZLPhotoPickerBrowserPhoto *photo = [[ZLPhotoPickerBrowserPhoto alloc] init];
            ZLPhotoPickerBrowserPhoto *photo = [ZLPhotoPickerBrowserPhoto photoAnyImageObjWith:url];
            //            photo.photoURL = [NSURL URLWithString:x];
            [assets addObject:photo];
            
        } else if ([url isKindOfClass:[NSData class]]) {
            UIImage *img = [UIImage imageWithData:url];
            ZLPhotoPickerBrowserPhoto *photo = [ZLPhotoPickerBrowserPhoto photoAnyImageObjWith:img];
            [assets addObject:photo];
        } else if ([url isKindOfClass:[NSString class]]){
            ZLPhotoPickerBrowserPhoto *photo = [[ZLPhotoPickerBrowserPhoto alloc] init];
            photo.photoURL = [NSURL URLWithString:url];
            [assets addObject:photo];
        }
    }
    // 图片游览器
    ZLPhotoPickerBrowserViewController *pickerBrowser = [[ZLPhotoPickerBrowserViewController alloc] init];
    // 淡入淡出效果
    pickerBrowser.status = UIViewAnimationAnimationStatusFade;
    // 数据源/delegate
    pickerBrowser.editing = NO;
    pickerBrowser.photos = assets;
    // 能够删除
    //        pickerBrowser.delegate = self;
    // 当前选中的值
    pickerBrowser.currentIndex = index;
    // 展示控制器
    
    if (viewController) {
        [pickerBrowser showPickerVc:viewController];
    } else {
        [pickerBrowser showPickerVc:[UIApplication sharedApplication].keyWindow.rootViewController];
    }
}

@end
